//
//  LeftMenuViewController.m
//  MeiLiProductModel
//
//  Created by B505 on 15/2/21.
//  Copyright (c) 2015年 孙晓林. All rights reserved.
//

#import "LeftMenuViewController.h"
#import "T4Marco.h"
#import "UIButton+Utils.h"
#import "SliderViewController.h"
#import "CollectionViewController.h"

static  NSString * const ChangeCityNotificationName = @"city";
static  NSString * const CityKeyName = @"cityname";
@interface LeftMenuViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *firstImageView;
@property (weak, nonatomic) IBOutlet UIButton *selectBtn;
@property (weak, nonatomic) IBOutlet UIImageView *secondImageView;
@property (weak, nonatomic) IBOutlet UIButton *collectBtn;
@property (weak, nonatomic) IBOutlet UIImageView *thirdImageView;
@property (weak, nonatomic) IBOutlet UIButton *cityBtn;
@property (weak, nonatomic) IBOutlet UIImageView *forthImageView;
@property (weak, nonatomic) IBOutlet UIButton *aboutBtn;
@property (weak, nonatomic) IBOutlet UIImageView *fifthImageView;
@property (weak, nonatomic) IBOutlet UIButton *loveBtn;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@end

@implementation LeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    //first
    _firstImageView.image = [UIImage imageNamed:@"menu_home"];
    [_selectBtn setTitleColor:HEXCOLOR(0x898989) selectedColor:HEXCOLOR(0x3B96F5)];
    [_selectBtn addTarget:self action:@selector(onClickSelectBtn:)];
    [_selectBtn setSelected:YES];
    
    //second
    _secondImageView.image = [UIImage imageNamed:@"menu_collect"];
    [_collectBtn setTitleColor:HEXCOLOR(0x898989) selectedColor:HEXCOLOR(0x3B96F5)];
    [_collectBtn addTarget:self action:@selector(onClickCollectBtn:)];
    //third
    _thirdImageView.image = [UIImage imageNamed:@"menu_city"];
    [_cityBtn setTitleColor:HEXCOLOR(0x898989) selectedColor:HEXCOLOR(0x3B96F5)];
    [_cityBtn addTarget:self action:@selector(onClickCityBtn:)];
    //forth
    _forthImageView.image = [UIImage imageNamed:@"menu_about"];
    [_aboutBtn setTitleColor:HEXCOLOR(0x898989) selectedColor:HEXCOLOR(0x3B96F5)];
    [_aboutBtn addTarget:self action:@selector(onClickAboutBtn:)];
    //fifth
    _fifthImageView.image = [UIImage imageNamed:@"menu_like"];
    [_loveBtn setTitleColor:HEXCOLOR(0x898989) selectedColor:HEXCOLOR(0x3B96F5)];
    [_loveBtn addTarget:self action:@selector(onClickLoveBtn:)];
    //line
    _lineView.backgroundColor = HEXCOLOR(0xDCDCDC);
    
    
    //添加监听
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(updateCity:)
                                                 name:ChangeCityNotificationName
                                               object:nil];
    
}

- (void)updateCity:(NSNotification *)city
{
    NSDictionary *infomationDic;
    infomationDic = [city userInfo];
    NSString *newBtnTitle = [NSString stringWithFormat:@"城市-%@",infomationDic[CityKeyName]];
    [_cityBtn setTitle:newBtnTitle];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
- (void)onClickSelectBtn:(UIButton *)btn
{
    T4_LOG_FUNC();
    [btn setSelected:YES];
    [_collectBtn setSelected:NO];
    [_cityBtn setSelected:NO];
    [_aboutBtn setSelected:NO];
    [_loveBtn setSelected:NO];
    [[SliderViewController sharedSliderController] showContentControllerWithModel:@"MenuViewController"];
}

- (void)onClickCollectBtn:(UIButton *)btn
{
    T4_LOG_FUNC();
    [btn setSelected:YES];
    [_selectBtn setSelected:NO];
    [_cityBtn setSelected:NO];
    [_aboutBtn setSelected:NO];
    [_loveBtn setSelected:NO];
    
    [[SliderViewController sharedSliderController] showContentControllerWithModel:@"MenuViewController"];
}

- (void)onClickCityBtn:(UIButton *)btn
{
    T4_LOG_FUNC();
    [btn setSelected:YES];
    [_collectBtn setSelected:NO];
    [_selectBtn setSelected:NO];
    [_aboutBtn setSelected:NO];
    [_loveBtn setSelected:NO];
    
    [[SliderViewController sharedSliderController] showContentControllerWithModel:@"CityViewController"];
}

- (void)onClickAboutBtn:(UIButton *)btn
{
    T4_LOG_FUNC();
    [btn setSelected:YES];
    [_collectBtn setSelected:NO];
    [_cityBtn setSelected:NO];
    [_selectBtn setSelected:NO];
    [_loveBtn setSelected:NO];
    
    [[SliderViewController sharedSliderController] showContentControllerWithModel:@"AboutUsViewController"];
}

- (void)onClickLoveBtn:(UIButton *)btn
{
    T4_LOG_FUNC();
    [btn setSelected:YES];
    [_collectBtn setSelected:NO];
    [_cityBtn setSelected:NO];
    [_aboutBtn setSelected:NO];
    [_selectBtn setSelected:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
